<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="white">
    <link rel="stylesheet" href="../dist/main.css">

</head>
<body>
<div id="genSet">

    <ul class="mui-table-view">
        <li class="mui-table-view-cell mui-collapse" id="changeCount">
            <a class="mui-navigate-right" href="#">跟单比例 <span id="count"></span></a>


        </li>
        <li class="mui-table-view-cell mui-collapse">
            <a class="mui-navigate-right" href="#">跟单手数计算公式</a>
            <div class="mui-collapse-content gs">
                <span>跟单手数 =</span><span class="spGs">信号源下单手数 <hr>信号源账户净值</span><span>x 资金比例 x 跟单账户净值</span>
            </div>
        </li>
        <li class="mui-table-view-cell mui-collapse">
            <a class="mui-navigate-right" href="#">示例</a>
            <div class="mui-collapse-content sp">
                <p>1.如果策略账户净值10,000美金下1手，您的账户净值是1,000美金，那么当设置为100%时下0.1手，设置为80%时0.08手，以此类推。</p>
                <p>2.如果策略账户净值10,000美金下1手，您的账户净值是50美金，那么当设置为100%时应该下0.005手，但由于交易平台支持最小下单手数为0.01手，所以您将不下单。</p>
                <p>3.如果一个策略的年化收益为100%，资金撤回为20%那么当设置为50%时相当于该策略对你的账户来说，年化收益为50%，资金撤回为10%。</p>
            </div>
        </li>
    </ul>

    <div class="mainBox">
        <div class="btns" style="display: none">
            <button class="mui-btn mui-btn-warning" id="sureGen">确定跟单</button>
            <button class="mui-btn mui-btn-warning mui-btn-outlined" id="cansel">暂不跟单</button>
        </div>
        <div class="btns2" style="display: none">
            <button  class="sureButton" id="cansel">返回</button>
            <button  class="canselButton" id="removeGen" >解除跟单</button>
        </div>
    </div>
    <div id="sheet1" class="mui-popover mui-popover-bottom mui-popover-action ">
        <!-- 可选择菜单 -->
        <ul class="mui-table-view">
            <li class="mui-table-view-cell canselList">
                <a href="#">立即平仓正在跟随的订单</a>
            </li>
            <li class="mui-table-view-cell canselList">
                <a href="#">与信号源同步平仓已跟随的订单</a>
            </li>
        </ul>
        <!-- 取消菜单 -->
        <ul class="mui-table-view">
            <li class="mui-table-view-cell">
                <a href="#sheet1"><b>取消</b></a>
            </li>
        </ul>
    </div>


</div>
<view></view>

</body>
</html>
<script src="../dist/main.js"></script>

<script>
    $("title").html(mt5Obj.title)
    var sourceLogin=sessionStorage.getItem("sourceLogin");
    /* 0  更改  1确认跟单*/
    var type=window.location.search.split("1")[1];
   if(type=="0"){
       $(".btns2").show();
   }else{
       $(".btns").show();
   }


    /*更改看自己原先跟单百分比  跟单获取剩余量*/
    $.ajax({
        url:mt5Obj.allUrl+"follow/get/myself/rate/surplus",
        success:function (data) {
            $("#count").html(data.data.rate+"%")
            sessionStorage.setItem("count",data.data.rate);
            sessionStorage.setItem("money",data.data.value);
            sessionStorage.setItem("count2",data.data.rate);
            if(type=="0"){
                $.ajax({
                    url:mt5Obj.allUrl+"follow/get/param",
                    data:{
                        sourceLogin:sessionStorage.getItem("sourceLogin")
                    },
                    success:function (data) {
                        $("#count").html(data.data.rate+"%")
                        sessionStorage.setItem("count",data.data.rate);

                    }
                })
            }

        }
    })

  //更改比例
  mui("body").on('tap','#changeCount',function(){
      if(type=="0"){
          rateO=sessionStorage.getItem("count")*1+sessionStorage.getItem("count2")*1
      }else{
          var rateO=sessionStorage.getItem("count")*1

      }
      var rate=$("#count").html().split("%")[0]*1/100
      var count=$("#count").html().split("%")[0]
      var value=sessionStorage.getItem("money")*1
      var money=(sessionStorage.getItem("money")*1*rate).toFixed(2)
      mui.confirm("<input type='text' value='"+count+"' class='mynumber' id='myNumber' min='0' max='100'   /><p id='changeMoney'>" + money + "</p>", "请输入跟单比例", ["取消", "确定"],
          function(e) {
              if(e.index == "1") {
                  if($("#myNumber").val()<=0){
                      mui.alert("最小比例为1");
                      $("#myNumber").val(1)
                  }
                  if(type=="0"){
                      $.ajax({
                          url:mt5Obj.allUrl+"follow/updateFollow",
                          type:"post",
                          data:{
                              sourceLogin:sessionStorage.getItem("sourceLogin"),
                              rate:$("#myNumber").val()
                          },
                          success:function (data) {
                              if(data.success){
                                  mui.alert("更改成功！")
                                  $("#count").html($("#myNumber").val()+"%")

                              }else{
                                  mui.alert("更改失败！")

                              }

                          }
                      })
                  }else{
                      $("#count").html($("#myNumber").val()+"%")

                  }

              }
          }, 'div')

      $('#myNumber').bind('input propertychange', function() {
            $("#changeMoney").html((value*$(this).val()/100).toFixed(2))

          if($(this).val()>rateO){
              mui.alert("跟单比例最多为"+rateO);
              $(this).val(rateO)
          }
          if($(this).val()>100){
              mui.alert("跟单比例最多为100");
              $(this).val(100)
          }

          if($(this).val()<0){
              mui.alert("跟单比例最小为1");
              $(this).val(1)
              $("#changeMoney").html((value*1/100).toFixed(2))
          }
      });



  })
    //暂不跟单
    mui("body").on('tap','#cansel',function(){
        goUrl("mowList","1");
        console.log(1)
    })
    //立即跟单
    mui("body").on('tap','#sureGen',function(){
        var rate=$("#count").html().split("%")[0]*1;
        if(rate<=0){
            mui.alert("跟单比例不能小于0");
        }else {
            $.ajax({
                url:mt5Obj.allUrl+"follow/createFollow",
                type:"post",
                data:{
                    sourceLogin:sessionStorage.getItem("sourceLogin"),
                    rate:$("#count").html().split("%")[0]*1,
                },
                success:function (data) {
                    if(data.success){
                        mui.alert("跟单成功",function(e) {
                            if(e.index == 0) {
                                goUrl("mowList","1");
                            }
                        });

                    }else{
                        mui.alert("跟单失败！")

                    }

                }
            })
        }

    })
    // 取消跟单
    mui("body").on('tap','#removeGen',function(){
        mui('#sheet1').popover('toggle');
    })
    mui("body").on('tap','.canselList',function(){
       var type;
       if($(this).children("a").html()=="立即平仓正在跟随的订单"){
           type=1;
       }else{
           type=2;
       }
      $.ajax({
          url:mt5Obj.allUrl+"follow/delete/param",
          type:"post",
          data:{
              sourceLogin:sourceLogin,
              riskType:type
          },
          success:function (data) {
              if(data.data){
                  mui.alert("取消成功",function(e) {
                      if(e.index == 0) {
                          goUrl("mowList","1");
                      }
                  });

              }
          }
      })
    })




</script>




